﻿<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WazeMap.aspx.cs" Inherits="GeoZoneWeb.WazeMap" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <title>חדשות ישראל על המפה</title>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
    <meta name="Description" content="חדשות ישראל על המפה"/>
    <meta name="Keywords" content="חדשות,ישראל,המפה"/> 
    <meta name="copyright" content="GeoZone"/>
    <meta name="Author" content="GeoZone"/>
    <meta name="ROBOTS" content="INDEX, FOLLOW"/>
    <meta http-equiv="Content-Language" content="he"/>
    <link rev="made" href="mailto:geozonegmail@gmail.com"/>
    <link rel="stylesheet" type="text/css" href="styles/styles.css"/>
    <script type="text/javascript" src="js/jquery-1.4.2.js"></script>
</head>
<body>
    <form id="form1" runat="server">
    <asp:ScriptManager runat="server" ID="ScriptManager1" />
    <div>
        <table style="width:100%;height:50px" cellpadding="0" cellspacing="0">
            <tr>
                <td>
                    <a class="footer_link" href="javascript:sethome()">קבע כעמוד בית</a> |
			 		<a class="footer_link" href="javascript:addbookmark()">הוסיפו למועדפים</a>
                </td>
            </tr>
            <tr align="center" valign="middle">
                <td align="center" valign="middle">
                    
                    <asp:Button ID="btnLocateMe" runat="server" Text="מצא" 
                        onclick="btnLocateMe_Click" />
                    <asp:TextBox ID="txtCurrLocation" Width="300" runat="server"></asp:TextBox>
                    <asp:DropDownList ID="ddlCurrentLocation" runat="server">
                        <asp:ListItem Selected="True" Text="" Value=""></asp:ListItem>
                    </asp:DropDownList>
                    <asp:Label ID="lblCurrLocation"  Font-Bold="true" Font-Names="Arial" ForeColor="Blue" runat="server" Text=":המיקום הרצוי"></asp:Label>
                </td>
            </tr>
        </table>
        <!-- f6d18d1e-9015-45fe-b6d8-cfda3a7428dd -->
        <div id="map" style="width:100%;height:580px;">
        </div>
        <script type="text/javascript">
            //----------------Global variables--------------------------//
            var markers, map;
            var drawControls, selectControl, selectedFeature;
            var bookmarkurl = "http://GeoZone/GeoZoneWeb/WazeMap.aspx";
            var bookmarktitle = "חדשות ישראל על המפה - GeoZone";
            var listOfMarkers = new Array();
            alert("array instance creation"); 
            //----------------------------------------------------------//
            
            //----------------Configurations----------------------------//
            g_waze_config = {
                div_id: "map", //id of the div that contains the map, must have width and height defined
                locale: "israel", //locale of the map, for now only 'israel' is supported
                center_lon: 34.79000, //center of the map longitude
                center_lat: 32.08600, //center of the map latitude
                zoom: 2, //zoom level of the map (0-10 supported)
                token: 'e99d8716-5a99-4907-a939-bb99dba7e025',//http://geozone/GeoZoneWeb/WazeMap.aspx
                alt_base_layer:"israel_colors",
                alt_map_servers: "http://ymap1.waze.co.il/wms-c/"
				//framed_cloud_image_url:"http://www.waze.co.il/test_api/cloud.png"
            };
            //-----------------------------------------------------------//
            
            //---------------------Functions-----------------------------//
            //function callback you can define that will be called once the map is ready

            
            //search callback called when search returns with the search results as parameter 'response'
            function find_callback(response) {
                alert('find_callback');
                /*[
	                //search result example:
	                {
		                //bounds that contain the this map feature (set map to this extent for closest zoom)
		                "bounds":{"bottom":32.0880470275879,
			 	                "left":34.7883338928223,
			 	                "right":34.7912673950195,
			 	                "top":32.0854721069336},
		                //location of the feature
		                 "location":{"lat":32.08560397003471,"lon":34.78999763465419},
		                //name of feature
	 	                "name":"ה' באייר, תל אביב - יפו"
	                }
	                //up to 9 more results
	                // ...
                ]*/
                //output the first (and best) result returned
                var first_result = response[0];
                var lonlat = new OpenLayers.LonLat(first_result.location.lon, first_result.location.lat);
                g_waze_map.map.setCenter(lonlat);
                var size = new OpenLayers.Size(30,30);//(36, 47);
                var offset = new OpenLayers.Pixel(-(size.w / 2), -size.h);
                var icon = new OpenLayers.Icon('images/news(30x30).gif', size, offset);
                markers = new OpenLayers.Layer.Markers("Markers");
                g_waze_map.map.addLayer(markers);
                //markers.addMarker(new OpenLayers.Marker(lonlat, icon));
                /*g_waze_map.map.addPopup(new OpenLayers.Popup.FramedCloud("הבית שלי", lonlat, null,
							"<div style='font-family:Arial;font-size:0.8em;'>" + first_result.name + "<div>",
							anchor = null, true, null));*/
				//addNewsMarker(first_result.location.lon, first_result.location.lat, 'משפחת פלומן', 'זה הבית של משפחת פלומן/עוגן','http://www.google.com','/images/home.jpg');
                //addNewsMarker(first_result.location.lon, first_result.location.lat,'2 הרוגים בתאונת-דרכים בירידות לים המלח','לילה קטלני: מכונית פרטית התנגשה חזיתית באוטובוס בכביש 31, סמוך לצומת חתרורים. שני נוסעי המכונית נהרגו, נהג האוטובוס, שהיה ריק מנוסעים, לא נפגע. ביפו נפצעו שני בני-אדם בהתהפכות רכבם. מצבו של אחד מהם קשה (חדשות)','http://www.ynet.co.il/articles/0,7340,L-3886420,00.html','/images/campus.jpg');
                addNewsMarker(first_result.location.lon, first_result.location.lat, "title", "description", "http://www.google.com", "1-1-2010", "Business");
			}

            function onWazeMapInit() {
                alert("onWazeMapInit");
                markers = new OpenLayers.Layer.Markers("Markers");
                g_waze_map.map.addLayer(markers);
                var map = g_waze_map.map;
                var shapes = new OpenLayers.Layer.Vector("Shapes");
                g_waze_map.map.addLayer(shapes);
                /*var pentagon = OpenLayers.Geometry.Polygon.createRegularPolygon(new OpenLayers.Geometry.Point(34.78441, 32.08946), 0.001, 5, 0);
                var pentagon_feature = new OpenLayers.Feature.Vector(pentagon);
                shapes.addFeatures([pentagon_feature]);
                var line = new OpenLayers.Geometry.LineString([
					new OpenLayers.Geometry.Point(34.79514, 32.09127),
					new OpenLayers.Geometry.Point(34.79544, 32.08985),
					new OpenLayers.Geometry.Point(34.79544, 32.08861),
					new OpenLayers.Geometry.Point(34.79544, 32.08736),
					new OpenLayers.Geometry.Point(34.79514, 32.08577)
				]);
                var line_feature = new OpenLayers.Feature.Vector(line);
                shapes.addFeatures([line_feature]);*/

                //-----------------Add features to the map---------------------//
                //g_waze_map.map.addControl(new OpenLayers.Control.PanZoomBar());
                //g_waze_map.map.addControl(new OpenLayers.Control.MouseToolbar());
                //g_waze_map.map.addControl(new OpenLayers.Control.LayerSwitcher({ 'ascending': false }));
                //g_waze_map.map.addControl(new OpenLayers.Control.Permalink());
                //g_waze_map.map.addControl(new OpenLayers.Control.Permalink('permalink'));
                //g_waze_map.map.addControl(new OpenLayers.Control.MousePosition());
                //g_waze_map.map.addControl(new OpenLayers.Control.OverviewMap());
                g_waze_map.map.addControl(new OpenLayers.Control.KeyboardDefaults());
                
                //------------------Shift+mousedown handler----------------------//
                var control = new OpenLayers.Control();
                OpenLayers.Util.extend(control, {
                    draw: function() {
                        // this Handler.Box will intercept the shift-mousedown
                        // before Control.MouseDefault gets to see it
                        this.box = new OpenLayers.Handler.Box(control,
                        { "done": this.notice },
                        { keyMask: OpenLayers.Handler.MOD_SHIFT });
                        this.box.activate();
                    },

                    notice: function(bounds) {
                        OpenLayers.Console.userError(bounds);
                    }
                });
                g_waze_map.map.addControl(control);
                //----------------------------------------------------------------//
                
                //-------------------------------------------------------------//
                
                /**
                * g_waze_map.find = function(term,callback_name,ignore_location)
                * @param term - the term to search for
                *
                * @param callback_name - callback to call when find returns, notice the the callback 
                * parameter is the NAME of the function as a String not the function itself
                *
                * @param ignore_location - if true, search will ignore the current position of the map and
                * results will be returned solely by string matching, disregarding proximity
                */
                //g_waze_map.find('החיד"א,חדרה', 'find_callback', true);
                for (markerJSIndex in listOfMarkers) {
                    //alert(listOfMarkers[markerJSIndex]);
                    eval(listOfMarkers[markerJSIndex]);
                }
            };

            //Functions to set favourites and homepage            
            function addbookmark() {
                if (document.all)
                    window.external.AddFavorite(bookmarkurl, bookmarktitle)
            }

            function sethome() {
                if (document.all)
                    document.body.style.behavior = "url(#default#homepage)"
                document.body.setHomePage(bookmarkurl);
            }

            function onPopupClose(evt) {
                //selectControl.unselect(selectedFeature);
                var feature = selectedFeature;
                g_waze_map.map.removePopup(feature.popup);
                feature.popup.destroy();
                feature.popup = null;
                selectedFeature = null;
            }

            function addNewsMarker(lon, lat,newsTitle,newsDescription,newsLink,newsPubDate,newsCategory) {
                var lonLatMarker = new OpenLayers.LonLat(lon, lat);
                var feature = new OpenLayers.Feature(markers, lonLatMarker);
                var size = new OpenLayers.Size(30, 30)//(31,25)
                var icon = new OpenLayers.Icon("images/news(30x30).gif", size);
                icon.offset = new OpenLayers.Pixel(0, -20)

                var marker = new OpenLayers.Marker(lonLatMarker, icon);
                // marker.feature = feature;
                var popHTML = '<div class="popUpStage" onclick="onPopupClose(null)" style="width:100%;height:100%"><table style="width:100%;height:100%;margin:0;padding:0" onclick="onPopupClose(null)" cellspacing="0" cellpadding="0"><tr><td align="center" valign="middle">' + newsTitle + '</td></tr><tr><td  align="center" valign="middle">' + newsPubDate + '</td></tr><tr valign="top"><td align="center" valign="middle">' + newsCategory + '</td></tr><tr valign="top"><td align="center" valign="middle">' + newsDescription + '</td></tr><tr><td align="center" valign="middle"><a href="' + newsLink + '" target="_blank">קישור לכתבה</a></td></tr></table></div>';
                var markerClick = function(evt) {
                    //console.log(popHTML)
                    if (selectedFeature != null) {
                        onPopupClose(null);
                    }
                    markerMouseOut()
                    selectedFeature = this;
                    if (this.popup == null) {
                        this.popup = new OpenLayers.Popup.FramedCloud(
			            "chicken",
			            lonLatMarker,
			            new OpenLayers.Size(302, 174),
			            popHTML,
			            this.icon, false, onPopupClose);
                        g_waze_map.map.addPopup(this.popup);
                        this.popup.show();
                    } else {
                        this.popup.toggle();
                    }
                    OpenLayers.Event.stop(evt);
                };
                var markerMouseOver = function(evt) {
                    icon.imageDiv.style.cursor = "pointer"
                    if (this.myOver == null) {
                        this.myOver = new OpenLayers.Popup("chicken",
														lonLatMarker,
														new OpenLayers.Size(30, 25),
														'<span class="alt">' + newsTitle + "</span>",
														false);
                        this.myOver.autoSize = true
                        this.myOver.backgroundColor = "#FFF"
                        this.myOver.border = "1px solid #000"
                        g_waze_map.map.addPopup(this.myOver); ;
                        this.myOver.show();
                    } else {
                        this.myOver.toggle();
                    }
                    OpenLayers.Event.stop(evt);
                }; //markerMouseOver

                var markerMouseOut = function(evt) {
                    if (this.myOver) {
                        g_waze_map.map.removePopup(this.myOver);
                        this.myOver.destroy();
                        this.myOver = null;
                    }
                } //markerMouseOut

                marker.events.register("mousedown", feature, markerClick);
                marker.events.register("mouseover", feature, markerMouseOver);
                marker.events.register("mouseout", feature, markerMouseOut);
                markers.addMarker(marker);
            }

            //----------------------------------------------------------------------------//
            
        </script>
        <script type="text/javascript" src="http://www.waze.co.il/js/WazeEmbeddedMap.js"></script>
    </div>
    </form>
</body>
</html>
